//
//  LoginGuideView.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/6.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "LoginGuideView.h"

#define mAnimationTime 0.5f
@interface LoginGuideView()

@property (nonatomic, strong) UIImageView *knowIcon;
@property (nonatomic, strong) UIImageView *gudieIcon;
@property (nonatomic, strong) UILabel *label;

@end


@implementation LoginGuideView

- (void)setupUI{
    
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5f];
    
    [self addSubview:self.label];
    [self addSubview:self.gudieIcon];
    [self addSubview:self.knowIcon];
}


- (void)setupLayout{
    
    self.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    
    {
        _label.size = CGSizeMake(KScreenWidth - 30, 50);
        _label.mj_x = 15;
        _label.mj_y = 180 + TJ_NavBarHeight;
    }
    
    {
        _gudieIcon.size = CGSizeMake(73, 155);
        _gudieIcon.mj_x = (KScreenWidth - _gudieIcon.width)/2.0;
        _gudieIcon.mj_y = _label.bottom + 20;
    }
    
    {
        _knowIcon.size = CGSizeMake(140, 50);
        _knowIcon.mj_x = (KScreenWidth - _knowIcon.width)/2.0;
        _knowIcon.mj_y = _gudieIcon.bottom + 17;
    }
}

#pragma mark - Public
- (void)show {
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window  addSubview:self];
    
    [UIView animateWithDuration:mAnimationTime animations:^{
        self.alpha = 1;
    }];
}

- (void)hide {
    
    [UIView animateWithDuration:mAnimationTime animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

#pragma mark - Private
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self hide];
}

#pragma mark - setter methods

- (void)setAttributedStr:(NSMutableAttributedString *)attributedStr{
    
    _label.attributedText = attributedStr;
}

#pragma mark - getter methods

- (UIImageView *)knowIcon{
    
    if (!_knowIcon) {
        _knowIcon = [UIImageView makeImageByImageName:@"meat_login_konw" cornerRadius:0];
    }
    return _knowIcon;
}


- (UIImageView *)gudieIcon{
    
    if (!_gudieIcon) {
        _gudieIcon = [UIImageView makeImageByImageName:@"meat_login_guide" cornerRadius:0];
    }
    return _gudieIcon;
}


- (UILabel *)label{
    
    if (!_label) {
        _label = [UILabel new];
        _label.backgroundColor = KWhiteColor;
        _label.textAlignment = NSTextAlignmentCenter;
    }
    return _label;
}


@end
